<template>
	<view class="master-income-record" v-if="isLoad">
		<view class="list-item ml-lg mr-lg pt-lg pb-lg" :class="[{'b-1px-t':index!=0}]"
			v-for="(item,index) in  list.data" :key="index">
			<view class="flex-between">
				<view class="f-mini-title c-title text-bold">
					{{item.type == 9?`直推${$t('action.attendantName')} ${item.coach_name} 完成服务`:`粉丝 ${item.nickName} 下单完成服务`}}
				</view>
				<view class="f-md-title ml-md">+{{item.cash}}
				</view>
			</view>
			<view class="pd-lg fill-body mt-md mb-md f-paragraph c-title radius-16" v-if="item.type!=9">
				<view :class="[{'mt-lg pt-lg b-1px-t':aindex!=0}]" v-for="(aitem,aindex) in item.order_goods"
					:key="aindex">
					<view class="flex-between">
						<span class="max-500 c-caption">{{aitem.goods_name}}<span
								class="ml-md">x{{aitem.num}}</span></span>
						<view>¥{{aitem.true_price}}</view>
					</view>
					<view class="flex-between mt-sm" v-if="aitem.material_type===1">
						<view class="c-caption">物料费</view>
						<view>¥{{aitem.material_price}} </view>
					</view>
					<view class="flex-between mt-sm">
						<view class="c-caption">返佣比例</view>
						<view :style="{color:subColor}">{{aitem.balance}}% </view>
					</view>
					<view class="flex-between mt-sm">
						<view>应得收益</view>
						<span class="max-470">
							{{`${aitem.cash_text} =`}}
							<span class="f-caption ml-sm" :style="{color:primaryColor}">¥<span
									class="f-mini-title">{{aitem.cash}}</span>
							</span>
						</span>
					</view>
				</view>
			</view>
			<view class="flex-center mt-sm">
				<view class="flex-1 f-caption c-caption">{{item.create_time}}</view>
				<view class="f-caption" :style="{color:primaryColor}" v-if="item.type==9">返佣{{item.balance}}%</view>
			</view>
			<view class="flex-center mt-sm">
				<view class="flex-1 f-caption c-caption">提现手续费</view>
				<view class="f-caption c-warning">-¥{{item.point_cash}}</view>
			</view>
		</view>
		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
		</load-more>
		<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1"></abnor>

		<view class="space-footer"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				isLoad: false,
				param: {
					page: 1,
					status: 2
				},
				list: {
					data: []
				},
				loading: true,
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
		}),
		async onLoad() {
			this.$util.showLoading()
			await this.initIndex()
			this.isLoad = true
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh();
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return;
			this.param.page = this.param.page + 1;
			this.loading = true;
			this.getList();
		},
		methods: {
			...mapMutations([]),
			async initIndex(refresh = false) {
				// #ifdef H5
				if (!refresh && this.$jweixin.isWechat()) {
					await this.$jweixin.initJssdk();
					this.$jweixin.wxReady(() => {
						this.$jweixin.hideOptionMenu()
					})
				}
				// #endif
				await this.getList()
				this.$util.setNavigationBarColor({
					bg: this.primaryColor
				})
			},
			initRefresh() {
				this.param.page = 1
				this.initIndex(true)
			},
			async getList() {
				let {
					list: oldList,
					param,
				} = this
				let newList = await this.$api.mine.commList(param);
				newList.data.map(item => {
					if (item.type !== 9) {
						let {
							material_type = 0
						} = item
						item.order_goods.map(aitem => {
							aitem.cash_text = material_type === 0 ?
								`${aitem.true_price}*${aitem.num}*${aitem.balance}%` :
								`(${aitem.true_price}+${aitem.material_price})*${aitem.num}*${aitem.balance}%`
						})
					}
				})

				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.$util.hideAll()
			},
			handerTabChange(index) {
				this.activeIndex = index;
				this.$util.showLoading()
				this.param.page = 1;
				this.getList()
			}
		}
	}
</script>


<style lang="scss">
	page {
		background: #fff
	}

	.master-income-record {

		.mine-menu-list {

			.money-info {
				font-size: 50rpx;

				.money {
					font-size: 70rpx;
				}
			}

		}

		.list-item {
			.item-tag {
				width: 24rpx;
				height: 24rpx;
			}

			.b-1px-t::before {
				border-top: 1px solid #ddd;
			}
		}
	}
</style>